import Vue from 'vue'
import App from './App'
import { $http } from '@escook/request-miniprogram'
// 将按需导入的 $http 挂载到 wx 顶级对象之上，方便全局调用
uni.$http = $http

// 配置请求根路径
$http.baseUrl = 'http://api.miao69.com/index.php'

// 请求开始之前做一些事情
$http.beforeRequest = function(options) {
  uni.showLoading({
    title: '数据加载中...',
  })
}

// 请求完成之后做一些事情
$http.afterRequest = function() {
  uni.hideLoading()
}

Vue.config.productionTip = false


// 提示框
const msg = (title, duration = 2000, mask = false, icon = 'none') => {
	if (Boolean(title) === false) {
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}


// 将数据存放本地缓存中
const set = (name, data) => {
	try {
		uni.setStorageSync(name, data)
	} catch (e) {
		console.log(e)
	}
}
// 从本地缓存中获取指定 name 对应的内容
const get = (name) => {
	let data
	try {
		data = uni.getStorageSync(name)
	} catch (e) {
		console.log(e)
	}
	return data
}
// 删除缓存
const remove = (name) => {
	let data
	try {
		data = uni.removeStorageSync(name)
	} catch (e) {
		console.log(e)
	}
	return data
}

// 挂载原型
Vue.prototype.$api = {
	msg,
	get,
	set,
	remove,


}


App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
